import { Component } from '@angular/core';
import { NavController,ItemSliding } from 'ionic-angular';
import { Task } from './task';


@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class TaskListPage {
  tasks:Array<Task>=[];

  constructor(public navCtrl: NavController) {

  }
  ionViewDidLoad(){
    this.tasks=[
      {title:'牛奶',status:'open'},
      {title:'鸡蛋',status:'open'},
      {title:'果汁',status:'open'},
      {title:'煎饼',status:'open'}
    ];
  }
  addTask(){
    let theNewTask:string=prompt("新任务");
    if(theNewTask !==''){
      this.tasks.push({title:theNewTask,status:'open'});
    }
 }
 markAsDone(slidingItem:ItemSliding,task:Task){
   task.status='done';
   slidingItem.close;

 }
 removeTask(task:Task){
   task.status='removed';
   let index=this.tasks.indexOf(task);
   if(index>-1){
     this.tasks.splice(index,1);
   }
   slidingItem.close();

 }
 doRefresh(refresher:any){
   setTimeout(()=>{
     this.httpData.getTasklist().subscribe(tasks=>{
       this,tasks=tasks;
       console.log{tasks};
     });
     refresher.complete();
   },2000);
 }

}

